import user from 'api/user.js'
import { arrayCopy } from 'utils'

export default {
	namespaced: true,
	actions: {
		login({ commit, dispatch }, { username, password }) {
			return user.login(username, password)
						.done(data => {
							if (data.status === 200){
								commit('user/login', [
										data.data.sessionid,
										data.data.name,
									],
									{ root: true },
								);
							}
						});
		},
		logout(context) {
			context.commit('user/logout', null, {root: true});
		},
	}
}